﻿using System;
using System.Linq;
using Sumen.Business;
using DevExpress.XtraSplashScreen;

using Sumen.Business.Permission;
using Sumen.Business.Presenter.Category;
using Sumen.Business.Presenter.Inventory;
using Sumen.Library.Enum;
using Sumen.Library.Froms;


namespace Sumen.GUI.Inventory
{
    public partial class Frm_Inventory : XtraUserControlKira
    {
        private EnumFormCode _fromCode = EnumFormCode.FrmInventory;
        #region Presenter

        private InventoryPresenter _inventoryPresenter;
        private StockPresenter _stockPresenter;

        #endregion

        #region From

        public Frm_Inventory()
        {
            InitializeComponent();
            _inventoryPresenter = new InventoryPresenter();
            _stockPresenter = new StockPresenter();
            buttonsArray1.capQuyen(new Permission(_fromCode.ToString(), ClsPublic.User.User_Username));
            //if (ClsPublic.SYSTEM_WRITELOG == "1")
            //{
            //    SysLogPresenter log = new SysLogPresenter();
            //    log.Add(_fromCode, EnumFormStatus.Modify, "", "");
            //}
        }

        private void Frm_Inventory_Load(object sender, EventArgs e)
        {
            LoadForm();
        }

        #endregion

        #region Control event

        private void buttonsArray1_btnEventProduceReports_click(object sender, EventArgs e)
        {
            LoadInventory(lookUpStock.EditValue + string.Empty);
        }

        private void buttonsArray1_btnEventClose_click(object sender, EventArgs e)
        {

        }

        #endregion

        #region Gridview event


        #endregion



        #region Method

        public override void LoadForm()
        {
            LoadInventory(lookUpStock.EditValue + string.Empty);
            LoadStock();
        }

        void LoadInventory(string pStockID)
        {
            var query = _inventoryPresenter.GetByKey(pStockID);
            gridControl1.DataSource = query.First();
            gridView1.ExpandAllGroups();
            gridView1.BestFitColumns();
        }

        void LoadStock()
        {
            lookUpStock.Properties.DataSource = _stockPresenter.GetAll();
        }

        #endregion

        private void chkShowPicture_CheckedChanged(object sender, EventArgs e)
        {
            if (chkShowPicture.Checked)
            {
                colPicture.VisibleIndex = 0;
                gridView1.RowHeight = 50;
            }
            else
            {
                colPicture.VisibleIndex = -1;
                gridView1.RowHeight = -1;
            }
        }

      







    }
}